package com.erms.lab.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.erms.common.annotation.Log;
import com.erms.common.enums.BusinessType;
import com.erms.lab.domain.SysPlan;
import com.erms.lab.service.ISysPlanService;
import com.erms.common.core.controller.BaseController;
import com.erms.common.core.domain.AjaxResult;
import com.erms.common.utils.poi.ExcelUtil;
import com.erms.common.core.page.TableDataInfo;

/**
 * 实验室建设规划情况Controller
 * 
 * @author guo
 * @date 2020-03-22
 */
@Controller
@RequestMapping("/lab/plan")
public class SysPlanController extends BaseController
{
    private String prefix = "lab/plan";

    @Autowired
    private ISysPlanService sysPlanService;

    @RequiresPermissions("lab:plan:view")
    @GetMapping()
    public String plan()
    {
        return prefix + "/plan";
    }

    /**
     * 查询实验室建设规划情况列表
     */
    @RequiresPermissions("lab:plan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SysPlan sysPlan)
    {
        startPage();
        List<SysPlan> list = sysPlanService.selectSysPlanList(sysPlan);
        return getDataTable(list);
    }

    /**
     * 导出实验室建设规划情况列表
     */
    @RequiresPermissions("lab:plan:export")
    @Log(title = "实验室建设规划情况", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SysPlan sysPlan)
    {
        List<SysPlan> list = sysPlanService.selectSysPlanList(sysPlan);
        ExcelUtil<SysPlan> util = new ExcelUtil<SysPlan>(SysPlan.class);
        return util.exportExcel(list, "plan");
    }

    /**
     * 新增实验室建设规划情况
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存实验室建设规划情况
     */
    @RequiresPermissions("lab:plan:add")
    @Log(title = "实验室建设规划情况", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SysPlan sysPlan)
    {
        return toAjax(sysPlanService.insertSysPlan(sysPlan));
    }

    /**
     * 修改实验室建设规划情况
     */
    @GetMapping("/edit/{planId}")
    public String edit(@PathVariable("planId") Long planId, ModelMap mmap)
    {
        SysPlan sysPlan = sysPlanService.selectSysPlanById(planId);
        mmap.put("sysPlan", sysPlan);
        return prefix + "/edit";
    }

    /**
     * 修改保存实验室建设规划情况
     */
    @RequiresPermissions("lab:plan:edit")
    @Log(title = "实验室建设规划情况", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SysPlan sysPlan)
    {
        return toAjax(sysPlanService.updateSysPlan(sysPlan));
    }

    /**
     * 删除实验室建设规划情况
     */
    @RequiresPermissions("lab:plan:remove")
    @Log(title = "实验室建设规划情况", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(sysPlanService.deleteSysPlanByIds(ids));
    }
}
